package com.youlu.campus.web.form;

import com.youlu.campus.entity.form.FormTaskConfig;
import com.youlu.campus.entity.form.UserFormTaskInfo;
import com.youlu.campus.service.form.FormTaskConfigService;
import com.youlu.campus.service.form.UserFormTaskInfoService;
import com.youlu.campus.web.common.base.RequestContext;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@RestController
public class FormController {
    @Autowired
    private FormTaskConfigService formTaskConfigService;
    @Autowired
    private UserFormTaskInfoService userFormTaskInfoService;

    @GetMapping("/mini-app/form/find-one")
    public QResult findOne(@RequestParam("formId") String formId) {
        FormTaskConfig form = formTaskConfigService.findOne(formId);
        UserFormTaskInfo userFormTaskInfo = userFormTaskInfoService.findBy(RequestContext.getUserId(), formId);
        if (Objects.isNull(userFormTaskInfo)) {
            form.setUserStatus("todo");
        } else {
            form.setUserStatus(userFormTaskInfo.getStatus());
        }
        return QResult.success(form);
    }

}
